package com.danger.Model.adapter;

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.danger.Activity.R;
import com.danger.Model.bean.FolderBean;
import com.danger.Util.ImageLoader;
import com.danger.Util.ImageLoaderUtil;

import java.util.List;

/**
 * Created by 俊 on 2016/5/31.
 */
public class ListDirAdapter extends ArrayAdapter<FolderBean> {

    private LayoutInflater mInflater;
    private List<FolderBean> mDatas;
    private Context context;


    public ListDirAdapter(Context context, List<FolderBean> objects) {
        super(context, 0, objects);
        this.context = context;
        mDatas = objects;
        mInflater = LayoutInflater.from(context);
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        ViewHolder holder = null;
        if (convertView == null) {
            convertView = mInflater.inflate(R.layout.item_popup_main, parent, false);
            holder = new ViewHolder(convertView);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        FolderBean bean = mDatas.get(position);
        //重置
        holder.mImage.setBackgroundResource(R.mipmap.dir);
        Log.i("TAG", "dir_path:" + bean.getFirstImgPath());
//        ImageLoader.getInstance(5, ImageLoader.Type.LIFO).loadImage(bean.getFirstImgPath(), holder.mImage);
        new ImageLoaderUtil(holder.mImage, bean.getFirstImgPath(), context).display();
        holder.mDirName.setText(bean.getName());
        holder.mDirCount.setText(bean.getCount() + "张");

        return convertView;
    }

    private class ViewHolder {

        ImageView mImage;
        TextView mDirName;
        TextView mDirCount;

        public ViewHolder(View view) {
            mImage = (ImageView) view.findViewById(R.id.dir_item_imageView);
            mDirName = (TextView) view.findViewById(R.id.dir_item_name_textView);
            mDirCount = (TextView) view.findViewById(R.id.dir_item_count_textView);
        }
    }
}
